//
//  MLWMapViewController.m
//  KITCHEN_STORIES
//
//  Created by dllo on 16/6/12.
//  Copyright © 2016年 MLW. All rights reserved.
//

#import "MLWMapViewController.h"
#import <MapKit/MapKit.h>   //地图框架
#import <CoreLocation/CoreLocation.h>   //定位
@interface MLWMapViewController ()<CLLocationManagerDelegate>

/** 声明一个地图视图 */
@property (nonatomic, retain) MKMapView *mapView;

//@property(strong, nonatomic) CLLocationManager *locationManager;
///** 经度 */
//@property(strong, nonatomic) UILabel *longitude;
///** 纬度 */
//@property(strong, nonatomic) UILabel *latitude;
///** 详细位置 */
//@property(strong, nonatomic) UILabel *location;
///** 城市名 */
//@property(strong, nonatomic) UILabel *cityLabel;
//
@end

@implementation MLWMapViewController

- (void)dealloc
{
    [_mapView release];
   // [_location release];
    [super dealloc];
}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    self.view.backgroundColor = [UIColor whiteColor];
    self.navigationItem.title = @"MAP";
    
    //创建地图:
    self.mapView = [[MKMapView alloc] initWithFrame:CGRectMake(0, 30, ScreenWidth, ScreenHeight - 64 - 49 - 30)];
    
    //地图类型:
    //1.MKMapTypeStandard 标准式的行政地图(会显示城市，街道等)
    //2.MKMapTypeSatellite 标准的卫星地图
    //3.MKMapTypeHybrid  混合地图(在卫星图上显示街道等名称)
    
    self.mapView.mapType = MKMapTypeStandard;
    //添加:
    [self.view addSubview:_mapView];
    
//    self.location = [[UILabel alloc] initWithFrame:CGRectMake(0, 30, ScreenWidth, ScreenWidth)];
//    [self.view addSubview:_location];
//    [_location release];
//     [self initializeLocationService];
    
}

//2)初始化定位管理器
//- (void)initializeLocationService {
//    
//    // 初始化定位管理器
//    _locationManager = [[CLLocationManager alloc] init];
//    
//    // 设置代理
//    _locationManager.delegate = self;
//    
//    // 设置定位精度到米
//    _locationManager.desiredAccuracy = kCLLocationAccuracyBest;
//    
//    // 设置过滤器
//    // 只有当设备在水平方向的位置改变超过该数值(以米为单位)指定的距离才会生成一次位置改变的信号
//    _locationManager.distanceFilter = kCLDistanceFilterNone;
//    
//    // 获得定位权限
//    // 1)
//    [_locationManager requestAlwaysAuthorization];
//    
//    // 开始定位
//    [_locationManager startUpdatingLocation];
//    
//    
//}
//
//- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation
//{
//    // 获取当前城市的名字
//    CLGeocoder *geocoder = [[CLGeocoder alloc] init];
//
//    [geocoder reverseGeocodeLocation:newLocation completionHandler:^(NSArray<CLPlacemark *> * _Nullable placemarks, NSError * _Nullable error) {
//        
//        if (placemarks.count > 0) {
//            
//            CLPlacemark *plactmark = [placemarks objectAtIndex:0];
//            
//            // 将获取的所有信息展示到label上
//            self.location.text = plactmark.name;
//            
//            NSString *city = plactmark.locality;
//            
//            if (!city) {
//                
//                // 四个直辖市信息无法通过locality获取,只能通过省份的方式获得(如果city为空,则为直辖市)
//                
//                city = plactmark.administrativeArea;
//                
//                NSLog(@"%@", city);
//                
//                _cityLabel.text = city;
//                
//                
//            }
//            
//            
//        }
//
//    }];
//    
//    // 系统会一直更新数据,直到选择停止更新,因为只需要获得一次经纬度即可,因此获取定位之后停止更新
//    [manager stopUpdatingLocation];
//
//}
//
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
